//
//  MainViewController.swift
//  微博222
//
//  Created by jessica on 15/11/8.
//  Copyright © 2015年 jessica. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    //跨swift操作OC方法加上@objc
    @objc private func composeDidClick(){
    
    print(__FUNCTION__)
    
    }
    //private 就相当于OC的.m文件
    override func viewDidLoad() {
        super.viewDidLoad()
//由于tabbar 是只读,要修改可以用KVC,否则后果很严重,不显示的哦
        
     let AddBtn = MainTabbar()
        setValue(AddBtn, forKey: "tabBar")
        
        //打印函数类名
        print(tabBar.classForCoder)
        //添加点击事件
        AddBtn.composeBtn.addTarget(self, action: "composeDidClick", forControlEvents: .TouchUpInside)
        
        
        //添加子控制器
        addChildViewControllers()
    
    }
    //重载
    private func addChildViewController(vc: UIViewController,title : String,imageName : String) {
    
        
        let nav = UINavigationController(rootViewController: vc)
        
self.tabBar.tintColor = UIColor.orangeColor()
        vc.title = title

       vc.tabBarItem.image = UIImage(named: imageName)
        
        addChildViewController(nav)
        
    }
    
    private func addChildViewControllers() {
        

        
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
        
        
        
    }
   
}

